package cn.edu.sjtu.se.dslab.project;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.log4j.Logger;

@Entity
@Table(name = "entity_zone")
public class EntityZone implements Serializable, Cloneable{
	private static final Logger logger = Logger.getLogger(EntityZone.class);
	
	private static final long serialVersionUID = 4701050682522117442L;
	
	private long id;
	private String name;
	private int size;
	private String entityUri;
	
	private Project project;
	
	private EntityZoneCategory entityZoneCategory;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	
	@Column(nullable = false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(nullable = false)
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	
//	@Column
//	public String getEntitys() {
//		return entitys;
//	}
//	public void setEntitys(String entitys) {
//		this.entitys = entitys;
//	}
	
	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "project_id", nullable = false)
	public Project getProject() {
		return project;
	}
	public void setProject(Project project) {
		this.project = project;
	}
	
	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "entity_zone_category_id", nullable = false)
	public EntityZoneCategory getEntityZoneCategory() {
		return entityZoneCategory;
	}
	public void setEntityZoneCategory(EntityZoneCategory entityZoneCategory) {
		this.entityZoneCategory = entityZoneCategory;
	}
	
	@Column(nullable = false)
	public String getEntityUri() {
		return entityUri;
	}
	public void setEntityUri(String entityUri) {
		this.entityUri = entityUri;
	}
	
	@Override
	public Object clone() {
		EntityZone ez = null;
		try{
			ez = (EntityZone)super.clone();
			ez.setId(0);
			ez.setProject(null);
		}catch(CloneNotSupportedException ex){
			ex.printStackTrace();
		}
		return ez;
	}
	
	
//	public void addEntitys(String[] entityUris){
//		if (entityUris == null) return;
//		StringBuilder sb = new StringBuilder();
//		for (String uri: entityUris){
//			sb.append(uri).append("|");
//		}
//		logger.info(sb.toString());
//		setEntitys(sb.toString());
//	}
//	
}
